//
//  LFMineViewController.m
//  LoveFruit
//
//  Created by 张令林 on 16/9/22.
//  Copyright © 2016年 张令林. All rights reserved.
//

#import "LFMineViewController.h"
#import "LFMineHelpController.h"
#import "LFMineYiJianController.h"
#import "LFOrderCell.h"
#import "LFPurseCell.h"
#import "LFTopView.h"
#import "LFMineFirstCell.h"
#import "LFMineOtherCell.h"
#import "LFAddressController.h"

#import "LFSettingController.h"
#import "LFGoodsController.h"
#import "LFShopViewController.h"
#import "LFMemberViewController.h"

#import "LdAccountOrderViewController.h"
#import "LFMineYouHuiQuanController.h"
//#import "LFHeaderView.h"

static NSString *cellid = @"cellid";
static NSString *firstCellid = @"firstCellid";
static NSString *purseCellid = @"purseCellid";
static NSString *orderCellid = @"orderCellid";
static NSString *otherCellid = @"otherCellid";

@interface LFMineViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, weak)LFTopView *topView;

@end

@implementation LFMineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //调用初始化方法
    [self setUpUI];
    
    UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:0 target:nil action:nil];
    [self.navigationItem setBackBarButtonItem:bar];
//    
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.hidden = YES;
    // 设置通知观察者
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(settBtnClick:) name:@"NotificationSettBtnClick" object:nil];
    // VIP通知观察者
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(memberButtonClick:) name:@"NotificationMemberButtonClick" object:nil];
    // 商品收藏通知观察者
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goodsButtonClick:) name:@"NotificationGoodsButtonClick" object:nil];
    // 店铺收藏通知观察者
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shopButtonClick:) name:@"NotificationShopButtonClick" object:nil];
}
// 设置
- (void) settBtnClick: (NSNotification*) aNotification{
    NSLog(@"收到通知了");
    LFSettingController *set = [LFSettingController new];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:set];
    [self.navigationController presentViewController:nav animated:YES completion:nil];
//    [self.navigationController pushViewController:set animated:YES];
}
// VIP
- (void) memberButtonClick: (NSNotification*) aNotification{
    LFMemberViewController *mem = [LFMemberViewController new];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:mem];
    [self.navigationController presentViewController:nav animated:YES completion:nil];
}
// 商品收藏
- (void) goodsButtonClick: (NSNotification*) aNotification{
    LFGoodsController *goods = [LFGoodsController new];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:goods];
    [self.navigationController presentViewController:nav animated:YES completion:nil];
}
// 店铺收藏
- (void) shopButtonClick: (NSNotification*) aNotification{
    LFShopViewController *shop = [LFShopViewController new];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:shop];
    [self.navigationController presentViewController:nav animated:YES completion:nil];
}
-(void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark 初始化方法
- (void)setUpUI{
    LFTopView *topView = [[LFTopView alloc] init];
    
    [self.view addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
        make.height.equalTo(@175);
    }];
    self.topView = topView;
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    tableView.delegate = self;
    tableView.dataSource = self;
    // 注册
    
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellid];
    [tableView registerNib:[UINib nibWithNibName:@"LFMineFirstCell" bundle:nil] forCellReuseIdentifier:firstCellid];
    [tableView registerNib:[UINib nibWithNibName:@"LFOrderCell" bundle:nil] forCellReuseIdentifier:orderCellid];
    [tableView registerNib:[UINib nibWithNibName:@"LFPurseCell" bundle:nil] forCellReuseIdentifier:purseCellid];
    [tableView registerNib:[UINib nibWithNibName:@"LFMineOtherCell" bundle:nil] forCellReuseIdentifier:otherCellid];
    [self.view addSubview:tableView];
    
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.view);
        make.top.equalTo(topView.mas_bottom);
    }];
    
    
//    self.view.backgroundColor = [UIColor randomColor];
//    // 头部视图
//    LFTopView *topView = [[LFTopView alloc] init];
//    [self.view addSubview:topView];
//    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.left.right.equalTo(self.view);
//        make.height.equalTo(@112);
//    }];
//    
//    self.headerView = topView;
//    
//    UITableView * tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
//    tableView.delegate = self;
//    tableView.dataSource = self;
//    // 注册
//    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellid];
//    [self.view addSubview:tableView];
//    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.right.bottom.equalTo(self.view);
//        make.top.equalTo(topView.mas_bottom);
//    }];
    
//    LFHeaderView *headerView = [[LFHeaderView alloc] init];
//    headerView.frame = CGRectMake(0, 0, self.view.frame.size.width, 55);
//    tableView.tableHeaderView = headerView;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 2) {
        return 1;
    }else{
        return 2;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLineEtched];
    if (indexPath.section == 0 && indexPath.row == 0) {
        return [tableView dequeueReusableCellWithIdentifier:firstCellid forIndexPath:indexPath];
    }
    if (indexPath.section == 0 && indexPath.row == 1) {
        LFOrderCell *orderCell = [tableView dequeueReusableCellWithIdentifier:orderCellid];
        return orderCell;
    }
    if (indexPath.section == 1 && indexPath.row == 0) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid forIndexPath:indexPath];
        cell.textLabel.text = @"我的钱包";
        cell.textLabel.font = [UIFont systemFontOfSize:15];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    if (indexPath.section == 1 && indexPath.row == 1) {
        return [tableView dequeueReusableCellWithIdentifier:purseCellid forIndexPath:indexPath];
    }else{
        return [tableView dequeueReusableCellWithIdentifier:otherCellid forIndexPath:indexPath];
    }
    
//    if (indexPath.section == 0 && indexPath.row == 0) {
//        
//        cell.textLabel.text = @"我的订单";
//        cell.imageView.image = [UIImage imageNamed:@"v2_my_address_icon"];
//    }
//    if (indexPath.section == 0 && indexPath.row == 1) {
//        cell.textLabel.text = @"我的店铺";
//        cell.imageView.image = [UIImage imageNamed:@"icon_mystore"];
//    }
//    if (indexPath.section == 1 && indexPath.row == 0) {
//        cell.textLabel.text = @"把爱鲜蜂分享给朋友";
//        cell.imageView.image = [UIImage imageNamed:@"v2_my_share_icon"];
//    }
//    if (indexPath.section == 2 && indexPath.row == 0) {
//        cell.textLabel.text = @"客服帮助";
//        cell.imageView.image = [UIImage imageNamed:@"v2_my_serviceonline_icon"];
//    }
//    if (indexPath.section == 2 && indexPath.row == 1) {
//        cell.textLabel.text = @"意见反馈";
//        cell.imageView.image = [UIImage imageNamed:@"v2_my_feedback_icon-1"];
//    }
//    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//    cell.selectionStyle = UITableViewCellSelectionStyleNone;
//    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0 && indexPath.row == 0) {
        return 44;
    }
    if (indexPath.section == 0 && indexPath.row == 1) {
        return 70;
    }
    if (indexPath.section == 1 && indexPath.row == 0) {
        return 44;
    }
    if (indexPath.section == 1 && indexPath.row == 1) {
        return 65;
    }else{
        return 200;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 6;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0.1;
}
 // 第一组点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0 && indexPath.row == 0) {
        NSLog(@"查看订单");
        
        LdAccountOrderViewController *lvc = [LdAccountOrderViewController new];
        [self.navigationController pushViewController:lvc animated:YES];
        
    }
}
- (IBAction)daiFuKuan:(id)sender {
    NSLog(@"待付款");
}
- (IBAction)daiShouHuo:(id)sender {
    NSLog(@"待收款");
}
- (IBAction)daiPingJia:(id)sender {
    NSLog(@"待评价");
}
- (IBAction)tuiKuanShouHou:(id)sender {
    NSLog(@"退款/售后");
}

// 第二组点击事件
- (IBAction)yuE:(id)sender {
    NSLog(@"余额");
}
- (IBAction)youHuiQuan:(id)sender {
    NSLog(@"优惠券");
   
    LFMineYouHuiQuanController *vc = [[LFMineYouHuiQuanController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    [self presentViewController:nav animated:YES completion:nil];
}
- (IBAction)jiFen:(id)sender {
    NSLog(@"积分");
}

// 第三组的按钮点击事件

- (IBAction)jiFenShangCheng:(id)sender {
    NSLog(@"积分商城");
}
- (IBAction)shouHuoDiZhi:(id)sender {
    NSLog(@"栗海云的Button");
    LFAddressController *VC = [LFAddressController new];

    UINavigationController *navC = [[UINavigationController alloc] initWithRootViewController:VC];
    [self.navigationController presentViewController:navC animated:YES completion:nil];
}
- (IBAction)woDeXiaoXi:(id)sender {
    NSLog(@"我的消息");
}
- (IBAction)keFuFanKui:(id)sender {
    NSLog(@"客服反馈");
}
- (IBAction)jiaMengHeZuo:(id)sender {
    NSLog(@"加盟合作");
}
- (IBAction)yaoQingFanKui:(id)sender {
    NSLog(@"邀请反馈");
}




//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

//    if (indexPath.section == 0 && indexPath.row == 0) {
//        NSLog(@"我的收货地址");
//        //[self.navigationController presentViewController: animated:YES completion:nil];
//    }
//    if (indexPath.section == 0 && indexPath.row == 1) {
//        
//        NSLog(@"我的店铺");
//        //[self.navigationController pushViewController:animated:YES];
//    }
//    
//    if (indexPath.section == 1 && indexPath.row == 0) {
//        NSLog(@"分享");
//    }
//    
//    if (indexPath.section == 2 && indexPath.row == 0) {
//        
//        NSLog(@"客服帮助");
//        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:[LFMineHelpController new]];
//        [self presentViewController:nav animated:YES completion:nil];
//    }
//    
//    if (indexPath.section == 2 && indexPath.row == 1) {
//        NSLog(@"意见反馈");
//        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:[LFMineYiJianController new]];
//        [self presentViewController:nav animated:YES completion:nil];
//    }
//}
@end
